package com.kahluastudios.mealfinder.desktop.client.recommendations;

import java.util.List;

import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.kahluastudios.mealfinder.desktop.client.MealfinderContext;
import com.kahluastudios.mealfinder.desktop.client.common.RestaurantSearchPanel;
import com.kahluastudios.mealfinder.desktop.client.services.RecommendationsService;
import com.kahluastudios.mealfinder.desktop.client.services.RecommendationsServiceAsync;
import com.kahluastudios.mealfinder.desktop.shared.RecommendationVO;

public class RecommendationsPanel extends VerticalPanel {

	private RecommendationsServiceAsync recommendationsService;
	
	private RestaurantSearchPanel searchPanel;
	private RecommendationsList recomendationList;
	
	public RecommendationsPanel(MealfinderContext context) {
		this.recommendationsService = GWT.create(RecommendationsService.class);
		
		this.searchPanel = new RestaurantSearchPanel();
		this.searchPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		this.searchPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		this.add(searchPanel);	
		
		this.recomendationList = new RecommendationsList();
		this.recomendationList.setWidth("100%");
		this.add(recomendationList);
		
		this.recommendationsService.getRecent(new AsyncCallback<List<RecommendationVO>>() {			
			public void onSuccess(List<RecommendationVO> result) {
				recomendationList.getDataProvider().getList().addAll(result);				
			}
			
			public void onFailure(Throwable caught) {
				
			}
		});				
	}

	public RestaurantSearchPanel getSearchPanel() {
		return this.searchPanel;
	}
	
}